<template>
  <!--登陆表单的容器-->
  <div class="login_container">
    <!--登陆区域-->
    <div class="login_box">
      <!--表单-->
      <el-form :model="loginForm" :rules="loginRules" ref="loginForm" class="login_form">
        <el-form-item label="账号" prop="username">
          <el-input v-model="loginForm.username" prefix-icon="el-icon-user-solid"></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="password">
          <el-input v-model="loginForm.password" prefix-icon="el-icon-lock"></el-input>
        </el-form-item>
        <el-form-item label="测试项目" prop="project">
          <el-select v-model="loginForm.project" placeholder="测试项目">
            <el-option label="多源综合监控管理系统" value="project0"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="测试级别" prop="level">
          <el-select v-model="loginForm.level" placeholder="测试级别">
            <el-option label="单元测试" value="unit"></el-option>
            <el-option label="部件测试" value="component"></el-option>
            <el-option label="配置项测试" value="configuration"></el-option>
            <el-option label="系统测试" value="system"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm('loginForm')">登录</el-button>
          <el-button @click="resetForm('loginForm')">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>

</template>

<script>
export default {
  name: 'Login',
  data() {
    return {
      loginForm: {
        username: '',
        password: '',
        verifyCode: '',
        project: '',
        level: ''
      },
      loginRules: {
        username: [
          { required: true, message: '请输入账号', trigger: 'blur' },
          { min: 1, max: 12, message: '长度在 1 到 12 个字符', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' },
          { min: 1, max: 12, message: '长度在 1 到 12 个字符', trigger: 'blur' }
        ],
        project: [
          { required: true, message: '请选择测试项目', trigger: 'blur' }
        ],
        level: [
          { required: true, message: '请输入测试级别', trigger: 'blur' }
        ]
      }
    };
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$router.push('/main');
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    }
  }
}
</script>

<style lang="less" scoped>
.login_container{
  height: 100%;
  background-color: cornflowerblue;
}
.login_box{
  width: 450px;
  height: 380px;
  background-color: #42b983;
  border-radius: 3px;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%,-50%);
}

.login_form{
  position: absolute;
  bottom: 0px;
  width: 100%;
  padding: 0px 20px;
  box-sizing: border-box;
}

</style>
